﻿@{
    ViewBag.Title = "固定资产列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script src="~/Content/layer-v3.1.1/layer/layer.js"></script>
@section scripts{
    <script type="text/javascript">

    //页面动态改动
    $(window).resize(function () {
        $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
    });

    //页面初始化
    $(document).ready(function () {
        DisableBackspace();

        //取下拉框的值
        loadComboboxData();

        bindGrid(); //绑定dg数据

        //设置datagrid数据网格、网格上查询条件框、外部布局框的高度，以适应页面高度
        $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");

        //查询按钮点击事件
        $("#btnsearch").on("click", function () {
            reSearch();
        });

        //按下键盘上enter键触发查询按钮的点击事件
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $("#btnsearch").trigger("click");
            }
        });

        //监听弹层页关闭按钮的点击事件
        $("#icon_close").on("click", function () {
            $("#layerPage").hide();
        });

    })

    //函数：绑定datagrid列表数据
    function bindGrid() {
        //获取查询条件
        var assetName = $("#txt_Name").textbox("getValue");//资产名称
        var assetID = $("#txt_AssetID").textbox("getValue");//固定资产编码
        var assetTypeID = $("#cmb_AssetType").combotree("getValue");//资产分类编码
        var isScrap = $("#cmb_IsScrap").combobox("getValue");//是否报废
        var assetBrand = $("#txt_Brand").textbox("getValue");//资产品牌
        var assetCurStorageID = $("#cmb_CurrentStorageID").combotree("getValue");//当前仓库（使用部门/分站）编码
        var assetManageDep = $("#txt_AssetManageDep").textbox("getValue");//资产管理部门
        var ambulanceNum = $("#txt_AmbulanceNum").textbox("getValue");//资产存放车辆车牌号
        //console.log(assetTypeID);
        //console.log($("#cmb_AssetType").combotree("getValue"));

        $('#grid').datagrid({
            width: 'auto',
            height: 'auto',
            fitColumns: true,
            striped: true, //条纹化
            singleSelect: true, //单选
            url: '@Url.Content("~/FixedAssets/FixedAssetsMaterial/GetAssetsList")',
            loadMsg: '数据加载中请稍后……',
            pagination: true,//启用分页
            rownumbers: true,//显示行号
            pageSize: 20,//设置 页容量
            pageList: [10, 15, 20],//设置 页容量下拉框
            queryParams: {
                assetName: assetName,
                assetID: assetID,
                assetTypeID: assetTypeID,
                isScrap: isScrap,
                assetBrand: assetBrand,
                assetCurStorageID: assetCurStorageID,
                assetManageDep: assetManageDep,
                ambulanceNum: ambulanceNum
            },
            columns: [[
               { title: '编码', field: 'BianMa', width: '3%', align: "center", sortable: false, hidden: true },
               { title: '固定资产编码', field: 'GuDingZiChanBianMa', width: '8%', align: "center", sortable: false },
               { title: '类别', field: 'LeiXing', width: '5%', align: "center", sortable: false },
               { title: '资产名称', field: 'ZiChanMingCheng', width: '8%', align: "center", sortable: false },
               { title: '主机序列号', field: 'ZhuJiXuLieHao', width: '8%', align: "center", sortable: false },
               { title: '品牌', field: 'PinPai', width: '4%', align: "center", sortable: false },
               { title: '型号', field: 'XingHao', width: '5%', align: "center", sortable: false },
               //{ title: '规格', field: 'GuiGe', width: '5%', align: "center", sortable: false },
               //{ title: '单位', field: 'DanWei', width: '5%', align: "center", sortable: false },
               //{ title: '数量', field: 'ShuLiang', width: '5%', align: "center", sortable: false },
               { title: '发票号码', field: 'FaPiaoHaoMa', width: '5%', align: "center", sortable: false },
               { title: '单价', field: 'DanJia', width: '5%', align: "center", sortable: false },
               {
                   title: '购建日期', field: 'GouJianRiQi', width: '7%', align: "center", sortable: false,
                   formatter: function (value, row, index) {
                       return $.formatDate(value);
                   }
               },
               {
                   title: '入库日期', field: 'RuKuRiQi', width: '7%', align: "center", sortable: false,
                   formatter: function (value, row, index) {
                       return $.formatDate(value);
                   }
               },
               { title: '使用部门/分站', field: 'DangQianCangKu', width: '7%', align: "center", sortable: false },
               { title: '当前存放点', field: 'DangQianCunFangDian', width: '7%', align: "center", sortable: false },
               { title: '当前车牌号码', field: 'DangQianChePaiHaoMa', width: '5%', align: "center", sortable: false },
               { title: '资产管理部门', field: 'ZiChanGuanLiBuMen', width: '5%', align: "center", sortable: false },
               { title: '资产管理人', field: 'ZiChanGuanLiRen', width: '5%', align: "center", sortable: false },
               //{
               //    title: '备注', field: 'BeiZhu', width: '5%', align: "center", sortable: false,
               //    formatter: function (value, row, index) {
               //        if (value) {
               //            return "<span title=\"" + value + "\">" + value + "</span>";//鼠标悬浮显示title文字
               //        } else {
               //            return "";
               //        }
               //    }
               //},
               {
                   title: '是否报废', field: 'ShiFouBaoFei', width: '4%', align: "center", sortable: false,
                   formatter: function (value, row, index) {
                       if (value) {
                           return "是";
                       } else {
                           return "否";
                       }
                   }
               },
               {
                   title: '报废申请单打印', field: 'New', width: '4%', align: "center", sortable: false, iconCls: 'icon-edit', formatter: formatNew
               },

            ]],
            toolbar: [{
                iconCls: 'icon-add',
                id: 'butnAdd',
                text: "资产新增",
                handler: function () {
                    showLayerPage('@Url.Content("~/FixedAssets/FixedAssetsMaterial/AssetsInfoEdit")' + '?State=new', '固定资产新增', '900px', '90%');
                }
            }, '-', {
                iconCls: 'icon-edit',
                id: 'butnEdit',
                text: "资产修改",
                handler: function () {
                    var r = $('#grid').datagrid('getSelected');
                    if (r) {
                        showLayerPage('@Url.Content("~/FixedAssets/FixedAssetsMaterial/AssetsInfoEdit")' + '?State=edit&Code=' + r.BianMa, '固定资产编辑', '900px', '90%');

                    }
                    else { $.messager.alert('提示信息', '请选择数据行！') }
                }
            }
            , '-',
            {
                iconCls: 'icon-remove',
                text: "资产删除",
                handler: function () {
                    var r = $('#grid').datagrid('getSelected');
                    if (r) {
                        //console.log(r);
                        deleteData(r.BianMa);
                    }
                    else { $.messager.alert('提示信息', '请选择数据行！') }
                }
            }
            ],
            //add 20191107 plq 双击行查看详情页
            onDblClickRow: function (rowIndex, rowData) {
                //console.log(rowData);
                showLayerPage('@Url.Content("~/FixedAssets/FixedAssetsMaterial/AssetsInfoEdit")' + '?State=edit&Code=' + rowData.BianMa, '固定资产编辑', '900px', '90%');
            }
            //onLoadSuccess: function (data) {
            //    console.log(data);
            //}
        })
        $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
    }
        //2019-10-28 sr 点击打印按钮
        function formatNew(value, rec) {
            var btn = '<a " onclick="openPrint(\'' + rec.GuDingZiChanBianMa + '\',\'' + rec.BianMa + '\')" href="javascript:void(0)">预览</a>';
            return btn;
        }
        //2019-10-28 sr 打开报废申请单打印预览页面
        function openPrint(GuDingZiChanBianMa, BianMa) {
            var url = '@Url.Content("~/Reports/DataForm.aspx?GuDingZiChanBianMa=")' + GuDingZiChanBianMa + '&BianMa=' + BianMa;
            //+ '&SendConfirmedTime=' + SendConfirmedTime + '&CompletionTime=' + CompletionTime
            window.open(url);
        }

    //重新查询
    function reSearch() {
        //获取查询条件
        var assetName = $("#txt_Name").textbox("getValue");//资产名称
        var assetID = $("#txt_AssetID").textbox("getValue");//固定资产编码
        var assetTypeID = $("#cmb_AssetType").combotree("getValue");//资产分类编码
        var isScrap = $("#cmb_IsScrap").combobox("getValue");//是否报废
        var assetBrand = $("#txt_Brand").textbox("getValue");//资产品牌
        var assetCurStorageID = $("#cmb_CurrentStorageID").combotree("getValue");//当前仓库（使用部门/分站）编码
        var assetManageDep = $("#txt_AssetManageDep").textbox("getValue");//资产管理部门
        var ambulanceNum = $("#txt_AmbulanceNum").textbox("getValue");//资产存放车辆车牌号

        //add20191107 plq start
        //解决查询按钮点击时 资产分类和当前仓库combotree组件未选择时 获取的值为undefined而不是""的问题
        //估计是easyui版本问题，浦东120同样的代码就没有这个问题
        //console.log(assetTypeID);
        //console.log($("#cmb_AssetType").combotree("getValue"));
        //console.log(assetCurStorageID);
        //console.log($("#cmb_CurrentStorageID").combotree("getValue"));
        if (assetTypeID == undefined) {
            assetTypeID = "";
        }
        if (assetCurStorageID == undefined) {
            assetCurStorageID = "";
        }
        //add20191107 plq end

        $('#grid').datagrid({
            pageNumber: 1,//点击查询返回第一页
            queryParams: {
                assetName: assetName,
                assetID: assetID,
                assetTypeID: assetTypeID,
                isScrap: isScrap,
                assetBrand: assetBrand,
                assetCurStorageID: assetCurStorageID,
                assetManageDep: assetManageDep,
                ambulanceNum: ambulanceNum
            }
        })
    }

    //资产删除
    function deleteData(code) {
        layer.confirm("确认要删除嘛？", {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                url: '@Url.Content("~/FixedAssets/FixedAssetsMaterial/DeleteData")',
                data: {
                    code: code
                },
                success: function (data) {
                    layer.alert(data, function (index) {
                        layer.close(index);
                        $("#btnsearch").trigger("click"); //重新查询
                    });
                }
            });
        })
    }


    //函数：加载combobox下拉框的值
    function loadComboboxData() {
        //固定资产分类
        $('#cmb_AssetType').combotree({
            url: '@Url.Content("~/FixedAssets/FixedAssetsDictionary/GetActiveAssetsTypeTree")',
            prompt: '--请选择--',
        });

        //使用部门/分站---当前仓库
        $('#cmb_CurrentStorageID').combotree({
            url: '@Url.Content("~/FixedAssets/FixedAssetsStorage/GetActiveAssetsStorageTree")',
            prompt: '--请选择--',
        });

        //是否报废
        $("#cmb_IsScrap").combobox({
            editable: false,
            prompt: '--请选择--',
            panelHeight: 120,
            data: [{
                value: 'True',
                text: '是'
            }, {
                value: 'False',
                text: '否',
                selected: true
            }]
        });
    }
    //2019-04-09 plq 显示弹层页面
    function showLayerPage(url, title, x, y) {
        $("#layerPageIframe").attr("src", url);
        $("#layerPage").css("width", x);
        $("#layerPage").css("height", y);
        $(".layerPage-title").html(title);
        $("#layerPage").show();
    }

    //2019-04-09 plq 隐藏弹层页面并重新查询页面
    function hideLayerPage() {
        $("#layerPage").hide();
        $("#layerPageIframe").attr("src", "");//iframe src置为空，防止下次打开时页面切换闪烁
        lnk = document.getElementById("btnsearch");
        lnk.click();
    }

    //2019-04-09 plq 隐藏弹层页面并重载页面
    function reload() {
        $("#layerPage").hide();
        $("#layerPageIframe").attr("src", "");//iframe src置为空，防止下次打开时页面切换闪烁
        location.reload();
    }

    //给easyui combotree增添清空按钮
    $.fn.combotree.defaults.icons = [{
        iconCls: 'icon-clear',
        handler: function (e) {
            $(e.handleObj.data.target).combotree('clear');
        }
    }];

</script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'固定资产列表',iconCls:'icon-custom-Entry'">
        <div id="SearchBar" data-options="region:'center'" style="overflow: hidden; padding: 10px">
            <table style="width:99%" cellpadding="0" cellspacing="5" border="0">
                <tr>
                    <td align="right" valign="middle" width="8%">资产名称：</td>
                    <td align="right" valign="middle" width="15%">
                        <input type="text" id="txt_Name" class="easyui-textbox" style="width:150px;" />
                    </td>
                    <td align="right" valign="middle" width="8%">固定资产编号：</td>
                    <td align="right" valign="middle" width="15%">
                        <input type="text" id="txt_AssetID" class="easyui-textbox" style="width:150px;" />
                    </td>
                    <td align="right" valign="middle" width="8%">分类：</td>
                    <td align="right" valign="middle" width="15%">
                        <input id="cmb_AssetType" class="easyui-combotree" style="width:150px;" />
                    </td>
                    <td align="center" valign="middle" width="8%">
                       是否报废
                    </td>
                    <td align ="center" valign="middle" width="15%">
                        <input id="cmb_IsScrap" class="easyui-combobox" style="width:150px;" />
                    </td>
                    <td align="center" valign="middle">
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="middle">品牌：</td>
                    <td align="right" valign="middle">
                        <input type="text" id="txt_Brand" class="easyui-textbox" style="width:150px;" />
                    </td>
                    <td align="right" valign="middle">使用部门/分站：</td>
                    <td align="right" valign="middle">
                        <input id="cmb_CurrentStorageID" class="easyui-combotree" style="width:150px;" />
                    </td>
                    <td align="right" valign="middle">资产管理部门：</td>
                    <td align="right" valign="middle">
                        <input type="text" id="txt_AssetManageDep" class="easyui-textbox" style="width:150px;" />
                    </td>
                    <td align="center" valign="middle">
                       存放车辆牌号
                    </td>
                    <td align="center" valign="middle">
                        <input type="text" id="txt_AmbulanceNum" class="easyui-textbox" style="width:150px;" />
                    </td>
                    <td align="center" valign="middle">
                        &nbsp;
                    </td>
                </tr>
            </table>
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="grid"></table>
        </div>
    </div>
</div>


<!--弹层页div-->
<div class="layerPage" id="layerPage" style="display:none;">
    <div class="layerPage-title" style="cursor: move;">弹层页</div>
    <span class="icon_close_box">
        <a class="icon_close" id="icon_close" href="javascript:;" style="background-image:url('@Url.Content("~/Images/icon/icon.png")')"></a>
    </span>
    <iframe id='layerPageIframe' style="width:100%;height:100%"></iframe>
</div>
<!--弹层页样式-->
<style>
    .layerPage {
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
        width: 900px;
        height: 650px;
        margin: 0;
        padding: 0;
        padding-top: 42px;
        background-color: #fff;
        border-radius: 2px;
        box-shadow: 1px 1px 50px rgba(0,0,0,.3);
        box-sizing: border-box;
    }

    .layerPage-title {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        padding: 0 80px 0 20px;
        height: 42px;
        line-height: 42px;
        border-bottom: 1px solid #eee;
        font-size: 14px;
        color: #333;
        overflow: hidden;
        background-color: #F8F8F8;
        border-radius: 2px 2px 0 0;
        text-overflow: ellipsis;
        white-space: nowrap;
        box-sizing: border-box;
        -moz-user-select: none;
        -o-user-select: none;
        -khtml-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }

    .layerPage iframe {
        border: none;
        width: 100%;
        height: 100%;
    }

    .icon_close_box {
        position: absolute;
        right: 15px;
        *right: 0;
        top: 15px;
        font-size: 0;
        line-height: initial;
        box-sizing: border-box;
    }

    .icon_close {
        display: inline-block;
        *display: inline;
        *zoom: 1;
        vertical-align: top;
        background-position: 1px -40px;
        cursor: pointer;
        width: 16px;
        height: 16px;
        margin-left: 10px;
        font-size: 12px;
        box-sizing: border-box;
        background-repeat: no-repeat;
    }
</style>
<style>
    .datagrid-header-row .datagrid-cell span {
        white-space: normal !important;
        word-wrap: normal !important;
    }
</style>

